import { Dimensions, PixelRatio } from 'react-native';
import { isIos } from './helper';

const screenSize = Dimensions.get('screen');
const windowSize = Dimensions.get('window');

// 屏幕尺寸
export const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = screenSize;
export const { width: WINDOW_WIDTH, height: WINDOW_HEIGHT } = windowSize;

//设计图
export const designWith = 375;
export const designHeight = 812;

// 底部导航栏高度
export const bottomSafeHeight = (SCREEN_HEIGHT - WINDOW_HEIGHT) / 2;

export const resize = (size: number, vertical = false) => {
  const scale = SCREEN_WIDTH / designWith;
  const scaleVertical = SCREEN_HEIGHT / designHeight;
  const newSize = size * (vertical ? scaleVertical : scale);
  const val = PixelRatio.roundToNearestPixel(newSize);
  return isIos() ? Math.round(val) : Math.round(val) - 1;
}